<template>
    <view class="container">
        <view class="fill_area">
            <view class="fill_small_title">
                企业基本情况
            </view>
            <view class="fill_list">
                <view class="">
                    企业名称
                </view>
                <u-input placeholder=''  v-model="userInfo.agentName" type="text" :border="border" :input-align="inputAlign" />
            </view>

            <view class="fill_list">
                <view class="">
                    注册地址
                </view>
                <u-input placeholder=''  v-model="userInfo.registAddr" type="text" :border="border"
                    :input-align="inputAlign" />
            </view>
            <view class="fill_list">
                <view class="">
                    联系地址
                </view>
                <u-input placeholder=''  v-model="userInfo.addr" type="text" :border="border" :input-align="inputAlign" />
            </view>
            <view class="fill_list">
                <view class="">
                    联系人
                </view>
                <u-input placeholder='' v-model="userInfo.linkMan" type="text" :border="border" :input-align="inputAlign" />
            </view>
            <view class="fill_list">
                <view class="">
                    联系方式
                </view>
                <u-input placeholder='' v-model="userInfo.unitLinkPhone" type="text" :border="border" :input-align="inputAlign" />
            </view>
            <view class="fill_list">
                <view class="">
                    法定代表人
                </view>
                <u-input placeholder='' v-model="userInfo.legalPerson" type="text" :border="border" :input-align="inputAlign" />
            </view>
            <view class="fill_list">
                <view class="">
                    统一社会信用代码
                </view>
                <u-input placeholder='' v-model="userInfo.agentCode" type="text" :border="border" :input-align="inputAlign" />
            </view>
            <view class="fill_list">
                <view class="">
                    企业类型
                </view>
                <u-input placeholder='' v-model="userInfo.organType" type="text" :border="border" :input-align="inputAlign" />
            </view>
            <view class="fill_list">
                <view class="">
                    注册资本
                </view>
                <u-input placeholder='' v-model="userInfo.capital" type="text" :border="border" :input-align="inputAlign" />
            </view>
        </view>

        <view class="fill_area">
            <view class="fill_small_title">
                新型墙体材料项目主要情况
            </view>
            <view class="fill_textarea">
                <view class="textarea_area">
                    <view class="">
                        <text>*</text>
                        产品名称、规格、产能及其组织生产执行的标准编号：
                    </view>
                    <view class="border_bottom">
                        <u-input v-for="(item,index) in standardNo" placeholder='请输入' v-model="item.value" type="textarea" :border="border" />
                        <view class="add_btn" @click="addViews" v-if="standardNo.length<5">
                            添加
                        </view>
                    </view>
                </view>
                <view class="textarea_area">
                    <view class="">
                        <text>*</text>
                        主要生产设备、设施名称、数量、规格和型号及其购置（建设）投资额（万元）：
                    </view>
                    <view class="border_bottom">
                        <u-input  v-for="(item,index) in devInfo" placeholder='请输入' v-model="item.value" type="textarea" :border="border" />
                        <view class="add_btn"  @click="addViews2" v-if="devInfo.length<5">
                            添加
                        </view>
                    </view>
                </view>
                <view class="textarea_area">
                    <view class="">
                        <text>*</text>
                        采用的节能利废工艺技术和取得的成效：
                    </view>
                    <view class="border_bottom">
                        <u-input maxlength="1000" placeholder='请输入（内容不超过1000字）' v-model="peinfo.getResult"
                            type="textarea" :border="border" />
                    </view>
                </view>

            </view>

            <view class="fill_area">
                <view class="fill_small_title">
                    企业申报说明
                </view>
                <view class="textarea_area">
                    <view class="border_bottom">
                        <u-input height="120" maxlength="2000" placeholder='填写说明：企业申报说明应当简要介绍新型墙体材料生产项目和建设情况，以及其他需要说明的内容，内容不超过2000字。'
                            v-model="peinfo.declareExplain " type="textarea" :border="border" />
                    </view>
                </view>
            </view>
            <view class="fill_area">
                <view class="fill_small_title">
                    厂区车间和主要生产设备设施照片
                </view>
                <view class="files_ts">
                    上传照片不超过10M，数量不超过9张
                </view>
                <view class="">
                    <u-upload max-count="9" max-size='10*1024*1024 ' :on-preview="handlePreview" :action="action"  @on-remove="onRemove" @on-success="onSuccess"></u-upload>
                </view>

            </view>

            <view class="fill_btn" @click="addbc">
                保存
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                itemCode:'',
                action: `${this.$basePath}/api/fileUpLoad?dir=image`,
                border: false,
                inputAlign: 'right',
                fileList: [],
                userInfo:{},
                peinfo: {
                    getResult:'',
                    declareExplain:'',
                },
                jglx: '',
                standardNo:[
                    {
                        value:''
                    }
                ],
                devInfo:[
                    {
                        value:''
                    }
                ]
            };
        },
        onLoad(option) {
            this.itemCode = option.itemCode;
            this.fileList = []
            this.peinfo={}
            this.getUserInfo() 
            this.userInfo = uni.getStorageSync('matterData')
           
        },
        created() {
          
        },
        methods:{
            handlePreview(file) {
                console.log(file);
            },
            onSuccess(data, index, lists){
                let currentFile = {name: '', url: ''};
                this.fileList.push(data.data);
                console.log(this.fileList)
            },
            onRemove(index){
            		if(this.fileList.length > 2 ){
            			this.fileList.splice(index,1);
            		}else{
            			this.fileList = [];
            		}
            },
            getUserInfo() {
                var that = this;
                this.$ajax({
                    url: '/api/wwwNews/getUserInfo',
                    method: 'post',
                    data: {
                        accessToken: window.localStorage.getItem('access_token'),
                        userType: window.localStorage.getItem('userType')
                    },
                    aysnc:false,
                }).then(res => {
                    if (res.code == 200) {
                        if (res.data.user.userType == 1) {
                            that.peinfo = res.data.legalInfo;
                        } else {
                            that.userInfo = res.data.userInfo;
                        }
                        that.user = res.data.user;
                        that.userType = res.data.user.userType;
                        if (that.user.organId.substr(1, 1) == '1' && (that.user.organId.substr(0, 1) == '1')) {
                            that.jglx = '机关编制机关';
                        };
                        if (that.user.organId.substr(1, 1) == '2' && (that.user.organId.substr(0, 1) == '1')) {
                            that.jglx = '机关编制事业';
                        };
                        if (that.user.organId.substr(1, 1) == '3' && (that.user.organId.substr(0, 1) == '1')) {
                            that.jglx = '机关编制群众团体';
                        };
                        if (that.user.organId.substr(1, 1) == '9' && (that.user.organId.substr(0, 1) == '1')) {
                            that.jglx = '机关编制其他';
                        };
                        if (that.user.organId.substr(1, 1) == '1' && (that.user.organId.substr(0, 1) == '5')) {
                            that.jglx = '民政社会团体';
                        };
                        if (that.user.organId.substr(1, 1) == '2' && (that.user.organId.substr(0, 1) == '5')) {
                            that.jglx = '民政民办非企业单位';
                        };
                        if (that.user.organId.substr(1, 1) == '3' && (that.user.organId.substr(0, 1) == '5')) {
                            that.jglx = '民政基金会';
                        };
                        if (that.user.organId.substr(1, 1) == '9' && (that.user.organId.substr(0, 1) == '5')) {
                            that.jglx = '民政其他';
                        };
                        if (that.user.organId.substr(1, 1) == '1' && (that.user.organId.substr(0, 1) == '9')) {
                            that.jglx = '工商企业';
                        };
                        if (that.user.organId.substr(1, 1) == '2' && (that.user.organId.substr(0, 1) == '9')) {
                            that.jglx = '工商个体工商户';
                        };
                        if (that.user.organId.substr(1, 1) == '3' && (that.user.organId.substr(0, 1) == '9')) {
                            that.jglx = '工商农民专业合作社';
                        };
                        if (that.user.organId.substr(1, 1) == '9' && (that.user.organId.substr(0, 1) == '9')) {
                            that.jglx = '工商其他';
                        };
                        console.log(that.jglx)
                    }
                });
            },
            addViews(index){
                var arr = {
                    value:''
                }
                this.standardNo.push(arr)
            },
            addViews2(index){
                var arr = {
                    value:''
                }
                this.devInfo.push(arr)
            },
            addbc() {
                var that = this;
                var data = {
                    declareExplain: that.peinfo.declareExplain, // 申报说明
                    devInfo1: that.devInfo[0].value, // 设备
                    devInfo2: that.devInfo[1] == undefined ? '' :  that.devInfo[1].value,
                    devInfo3: that.devInfo[2] == undefined ? '' :  that.devInfo[2].value,
                    devInfo4: that.devInfo[3] == undefined ? '' :  that.devInfo[3].value,
                    devInfo5: that.devInfo[4] == undefined ? '' :  that.devInfo[4].value,
                    getResult: that.peinfo.getResult, // 采用节能
                    images: that.fileList,
                    itemCode: that.itemCode,
                    registAddr: that.userInfo.registAddr,
                    standardNo1: that.standardNo[0].value, // 产品
                    standardNo2: that.standardNo[1] == undefined ? '' :  that.standardNo[1].value,
                    standardNo3: that.standardNo[2] == undefined ? '' :  that.standardNo[2].value,
                    standardNo4: that.standardNo[3] == undefined ? '' :  that.standardNo[3].value,
                    standardNo5: that.standardNo[4] == undefined ? '' :  that.standardNo[4].value,
                };
                if (data.devInfo1 == '' && data.devInfo2 == '' && data.devInfo3 == '' && data.devInfo4 == '' &&
                    data.devInfo5 == '') {
                    uni.showToast({
                        title: '请至少填一项主要生产设备、设施名称、数量、规格和型号及其购置（建设）投资额！',
                        icon:'none'
                    });
                    return false;
                }
                if (data.standardNo1 == '' && data.standardNo2 == '' && data.standardNo3 == '' && data.standardNo4 ==
                    '' && data.standardNo5 == '') {
                    uni.showToast({
                        title: '请至少填一项产品名称、规格、产能及其组织生产执行的标准编号！',
                        icon:'none'
                    });
                    return false;
                }
                if (data.declareExplain == '') {
                   uni.showToast({
                        title: '企业申报说明不能为空！',
                        icon:'none'
                    });
                    return false;
                }
                if (data.getResult == '') {
                    uni.showToast({
                        title: '采用的节能利废工艺技术和取得的成效不能为空！',
                        icon:'none'
                    });
                    return false;
                }
                this.$ajax({
                    url: '/api/insertFormDeclaration',
                    headers: {
                        userType: window.localStorage.getItem('userType'),
                        accessToken: window.localStorage.getItem('access_token'),
                    },
                    method: 'POST',
                    contentType: "application/json",
                    data: data
                }).then(res => {
                    if (res.code == 200) {
                        uni.showToast({
                            title: '保存成功！',
                            icon:'none'
                        });
                        setTimeout(function() {
                            uni.navigateTo({
                            	url: '/pages/matter/uploadFile'
                            });
                        }, 1000);
                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon:'none'
                        });
                    }
                });
            },
        }
    }
</script>

<style scoped lang="less">
    .container {
        padding: 0 30rpx 30rpx;
    }
    .add_btn{
        display: flex;
        justify-content: center;
        align-items: center;
        width: 120rpx;
        border: 1rpx solid #5b96ff;
        color: #5b96ff;
        border-radius: 10rpx;
        font-size: 36rpx ;
        margin:  0 auto;
    }

    .fill_area {
        margin-top: 30rpx;
        .fill_small_title {
            font-size: 36rpx;
            position: relative;
            padding-left: 20rpx;

            &::after {
                position: absolute;
                top: 50%;
                left: 0;
                width: 6rpx;
                content: '';
                height: 75%;
                transform: translateY(-50%);
                background-color: #5b96ff;
            }
        }

        .fill_list {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 28rpx;
            color: #333;
            height: 104rpx;
            border-bottom: 1rpx solid #f1f1f1;

            view {
                display: flex;
                align-items: center;
                margin-right: 30rpx;

                text {
                    color: #e21919;
                }
            }

        }
    }

    .textarea_area {
        font-size: 28rpx;
        color: #333;
        margin-top: 30rpx;

        view {
            margin-bottom: 20rpx;

            &.border_bottom {
                border-bottom: 1rpx solid #f1f1f1;
            }

            text {
                color: #e21919;
            }
        }
    }

    .fill_btn {
        background-color: #5b96ff;
        color: #fff;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 32rpx;
        margin-top: 40rpx;
        margin-bottom: 60rpx;
        height: 80rpx;
        border-radius: 10rpx;
    }

    .files_ts {
        margin-top: 30rpx;
        font-size: 28rpx;
        color: #969696;
    }
</style>
